// user/enshrine/enshrine.js
import http from '../../http'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		status: 1,
		enshrineList: [],
		enshrineList1: []
	},
	gain() {
		// 先检查是否登录
		if (!wx.getStorageSync('userId')) {
			wx.showToast({
				title: '请先登录',
				icon: 'error'
			});
			return; // 直接返回，不执行后面的代码
		}
		wx.showLoading({
			title: '加载中...'
		});
		http.post({
			url: '/Collect/List',
			data: {
				user_id: wx.getStorageSync('userId'),
				type: this.data.status
			},
			then: (res) => {
				console.log('收藏列表', res);
				if (this.data.status == 1) {
					this.setData({
						enshrineList: res.data.data
					}, () => {
						wx.hideLoading()
					})
				} else {
					this.setData({
						enshrineList1: res.data.data
					}, () => {
						wx.hideLoading()
					})
				}
			}
		})
	},
	onTabsChange(event) {
		this.setData({
			status: event.detail.value
		}, () => {
			this.gain()
		})
	},
	onDelete(e) {
		http.post({
			url: '/Collect/Delete',
			data: {
				id: e.currentTarget.dataset.id,
				user_id: wx.getStorageSync('userId'),
			},
			then: (res) => {
				console.log('取消拍卖会收藏', res);
				if (res.data.code == 1) {
					wx.showToast({
						title: '已删除',
						icon: 'success',
						duration: 2000
					})
					this.gain()
				} else {
					wx.showToast({
						title: res.data.msg,
						icon: 'error',
					})
				}
			}
		})
	},
	onDelete1(e) {
		http.post({
			url: '/Collect/Delete',
			data: {
				items_id: e.currentTarget.dataset.id,
				user_id: wx.getStorageSync('userId'),
			},
			then: (res) => {
				console.log('取消拍品收藏', res);
				if (res.data.code == 1) {
					wx.showToast({
						title: '已删除',
						icon: 'success',
						duration: 2000
					})
					this.gain()
				} else {
					wx.showToast({
						title: res.data.msg,
						icon: 'error',
					})
				}
			}
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		wx.loadFontFace({
			family: 'din',
			source: 'url("https://pm.yunhuzh.com/uploads/din.ttf")',
		})
		wx.loadFontFace({
			family: 'dakai',
			source: 'url("https://pm.yunhuzh.com/uploads/阿里妈妈东方大楷.ttf")',
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {
		this.gain()
	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})